package pierwszy.wordPressPageObjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.LoadableComponent;
import org.testng.Assert;

public class AdminLoginPage extends LoadableComponent <AdminLoginPage>{
	WebDriver driver;
	@FindBy (how=How.ID, using="user_login")
	WebElement email;
	@FindBy (how=How.ID, using="user_pass")
	WebElement password;
	@FindBy (how=How.ID, using="wp-submit")
	WebElement submit;
	
	public AdminLoginPage(WebDriver driver){
		this.driver = driver;
		driver.manage().window().maximize();
		PageFactory.initElements(driver, this);
		//driver.get("http://pageobjectpattern.wordpress.com/wp-admin");
	}
	
	public AllPostsPage login(){
		email.sendKeys("wojciech.pulawski@gmail.com");
		password.sendKeys("Sm028xf?");
		submit.click();
		
		return PageFactory.initElements(driver, AllPostsPage.class);
	}

	@Override
	protected void isLoaded() throws Error {
		// TODO Auto-generated method stub
		driver.get("http://pageobjectpattern.wordpress.com/wp-admin");
	}

	@Override
	protected void load() {
		// TODO Auto-generated method stub
		Assert.assertTrue(driver.getCurrentUrl().contains("wp-admin"));
	}
}
